<?php
/**
 * Created by PhpStorm.
 * User: mr_lee
 * Date: 2017/11/1
 * Time: 下午4:52
 */

namespace app\macht\controller;



use app\common\model\LoginUsers;
use think\Controller;
use think\Session;

class Usersetting extends MachBase
{
    public function usersetting(){
         if(request()->isAjax()){
             $map['id']=Session::get('user.uid');
             $old_password=request()->post('old_password');
             $LoginUser=new LoginUsers();
             $userinfo=$LoginUser->where($map)->find();
             if($userinfo){
                 if($userinfo['password']==MD5($old_password)){
                     $data['password']=MD5(request()->post('new_password'));
                     $sa=$LoginUser->save($data,$map);
                     if($sa){
                         $arr=array('code'=>0,'message'=>"修改成功");
                     }else{
                         $arr=array('code'=>1,'message'=>"修改失败");
                     }
                 }else{
                     $arr=array('code'=>2,'message'=>"原始密码不正确");
                 }
             }else{
                 $arr=array('code'=>3,'message'=>"非法操作");
             }
            return json($arr);
         }else{
             return $this->fetch();
         }
    }

}